package com.mindmax.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mindmax.user.domain.TenantResource;
import com.mindmax.user.service.ITenantResourceService;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租户权限关系Controller
 * 
 * @author cab
 * @date 2024-04-23
 */
@RestController
@DataSource(value = DataSourceType.YT_ADMIN)
@RequestMapping("/system/tenantResource")
public class TenantResourceController extends BaseController
{
    @Autowired
    private ITenantResourceService tenantResourceService;

    /**
     * 查询租户权限关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:tenantResource:list')")
    @GetMapping("/list")
    public TableDataInfo list(TenantResource tenantResource)
    {
        startPage();
        List<TenantResource> list = tenantResourceService.selectTenantResourceList(tenantResource);
        return getDataTable(list);
    }

    /**
     * 导出租户权限关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:tenantResource:export')")
    @Log(title = "租户权限关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TenantResource tenantResource)
    {
        List<TenantResource> list = tenantResourceService.selectTenantResourceList(tenantResource);
        ExcelUtil<TenantResource> util = new ExcelUtil<TenantResource>(TenantResource.class);
        util.exportExcel(response, list, "租户权限关系数据");
    }

    /**
     * 获取租户权限关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tenantResource:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tenantResourceService.selectTenantResourceById(id));
    }

    /**
     * 新增租户权限关系
     */
    @PreAuthorize("@ss.hasPermi('system:tenantResource:add')")
    @Log(title = "租户权限关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TenantResource tenantResource)
    {
        return toAjax(tenantResourceService.insertTenantResource(tenantResource));
    }

    /**
     * 修改租户权限关系
     */
    @PreAuthorize("@ss.hasPermi('system:tenantResource:edit')")
    @Log(title = "租户权限关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TenantResource tenantResource)
    {
        return toAjax(tenantResourceService.updateTenantResource(tenantResource));
    }

    /**
     * 删除租户权限关系
     */
    @PreAuthorize("@ss.hasPermi('system:tenantResource:remove')")
    @Log(title = "租户权限关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tenantResourceService.deleteTenantResourceByIds(ids));
    }
}
